package com.rising.face.lock.locksupport;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author: rising
 * @Description:
 * @Date: create in 2021/1/30 18:06
 */
public class LockSupportTest {

    public static void main(String[] args) {

        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("a 进来了");
                LockSupport.park();
                LockSupport.park();
                System.out.println("a 被唤醒");
            }
        }, "a");
        a.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Thread b = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("b 进来了");
                LockSupport.unpark(a);
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                LockSupport.unpark(a);
                System.out.println("b 执行唤醒");
            }
        }, "b");

        b.start();
    }

}
